package com.sdkx.app.ViewModel;

import com.sdkx.app.model.TrackLine;
import com.sdkx.app.model.TrackPoint;

import org.litepal.LitePal;

import java.util.List;

/**
 * 航迹管理类
 */
public class TrackLineManager {
    /**
     * 获取所有航迹,如果name为null则返回所有数据，否则返回所有名称类似name的数据
     * @return
     */
    public static List<TrackLine> getItems(String name)
    {
        if(name==null)
            return LitePal.findAll(TrackLine.class);
        else
            return LitePal.where("name like ?", name).find(TrackLine.class);
    }

    public static List<TrackLine> getItemsLimit(int limit ,int offset){
        return LitePal.offset(offset).limit(limit).find(TrackLine.class);
    }
    /**
     * 获取指定的航迹
     * @param name
     * @return
     */
    public static TrackLine getItem(String name){
        List<TrackLine> trackLines = LitePal.where("name = ?", name).find(TrackLine.class);
        if(trackLines.size()>0)
            return trackLines.get(0);
        else
            return null;
    }

    /**
     * 检查名称是否已经使用
     * @param name
     * @return
     */
    public static boolean Contains(String name){
        return LitePal.where("name = ?",name).count(TrackLine.class)>0;
    }

    /**
     * 新建航迹
     * @param trackLine
     * @return
     */
    public static boolean insert(TrackLine trackLine){
        if(trackLine==null)
            return false;
        return trackLine.save();
    }

    /**
     * 删除指定航迹
     * @param name
     */
    public static void delete(String name){
        LitePal.deleteAll(TrackLine.class,"name = ?",name);
    }

    /**
     * 删除所有航迹
     */
    public static void deleteAll(){
        LitePal.deleteAll(TrackLine.class);
    }



}
